const httpProxy = require('http-proxy');
const http = require('http');
 
// 创建代理服务器实例
const proxy = httpProxy.createProxyServer({});
 
// 监听代理请求错误
proxy.on('error', (err, req, res) => {
  res.writeHead(500, {
    'Content-Type': 'text/plain'
  });
  res.end('Something went wrong: ' + err.message);
});
 



// 创建HTTP服务器并定义请求处理逻辑
const server = http.createServer((req, res) => {
  // 代理请求到目标服务器
  proxy.web(req, res, { target: 'https://movie.douban.com/top250' });
});
 






server.listen(3000);
 
console.log('Proxy server is running on port 3000');